﻿using System;
using System.Windows.Forms;
using FoundationClass;
using FoundationClass.Entity;

namespace P2MARY_INTERNET.Controls
{
    public partial class EmployeeDialog : Form
    {
        public EmployeeDialog()
        {
            InitializeComponent();
        }

        public User Employee;
        

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text.Trim().Length == 0 || txtPassword.Text.Length == 0)
                {
                    lblValidate.Text = @"กรูณากรอกข้อมูลให้ครบ";
                    return;
                }
                if (SecurityHandler.GetUser(txtUserName.Text) != null)
                {
                    lblValidate.Text = @"กรุณาใช้ Id อื่น";
                    return;
                }
                Employee = new User
                    {
                        Id = txtUserName.Text,
                        Username = txtUserName.Text,
                        Address = txtAddress.Text,
                        DateStart = dateStart.Value,
                        FirstName = txtEmpName.Text,
                        Gender = radMale.IsChecked ? "M" : "F",
                        LastName = txtEmpLastName.Text,
                        NickName = txtNickName.Text,
                        Password = txtPassword.Text,
                        Phone = txtTel.Text,
                        Position = drpPosition.SelectedIndex,
                        Wage = txtWage.Value,
                        WorkTime = drpWorkTime.Text
                    };
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
